CXX=g++
CFLAGS=-Wall
CXXFLAGS=-Wall -Iinclude `pkg-config opencv --cflags` -g
LDFLAGS=`pkg-config opencv --libs`


COMMON_DEPS   = obj/common/transmit.o obj/common/capture.o obj/common/motor.o obj/common/sensors.o obj/common/sensors.o obj/common/util.o
VIDEO_DEPS    = obj/common/transmit.o obj/common/capture.o obj/video/video.o
CONTROLS_DEPS = obj/common/transmit.o obj/common/motor.o   obj/common/util.o  obj/common/sensors.o obj/controls/controls.o
IMU_DEPS      = obj/common/transmit.o obj/common/sensors.o obj/common/util.o  obj/imu/imuServer.o


.PHONY: all
.PHONY: common
.PHONY: video
.PHONY: controls
.PHONY: imu
.PHONY: tests
.PHONY: clean


all: clean common video controls imu tests


common: $(COMMON_DEPS)

video: $(VIDEO_DEPS)
	$(CXX) $(LDFLAGS) $^ -o bin/$@

controls: $(CONTROLS_DEPS)
	$(CXX) $(LDFLAGS) $^ -o bin/$@

imu: $(IMU_DEPS)
	$(CXX) $(LDFLAGS) $^ -o bin/$@

tests: $(COMMON_DEPS) obj/controls/test.o obj/imu/test.o
	$(CXX) $(LDFLAGS) $(COMMON_DEPS) obj/controls/test.o -o bin/test_controls
	$(CXX) $(LDFLAGS) $(COMMON_DEPS) obj/imu/test.o -o bin/test_imu


obj/common/%.o: common/%.cpp include/rov/%.h
	$(CXX) $(CXXFLAGS) -c -o $@ $<

obj/video/%.o: video/%.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<

obj/controls/%.o: controls/%.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<

obj/imu/%.o: imu/%.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<


clean:
	rm -rf obj/common/* obj/controls/* obj/imu/* obj/video/* bin/*
